package com.tuantuan.common.base.result;

import com.tuantuan.common.base.common.IResponseErrorCode;

/**
 * @author: wangqinmin
 * @date : 2020/10/11
 * @description: 仰天大笑出门去，我辈岂是蓬蒿人
 */
public enum ApiCode implements IResponseErrorCode {

    /**
     * 失败
     */
    FAILED(0, "操作失败"),
    /**
     * 成功
     */
    SUCCESS(1, "执行成功");

    private final long code;
    private final String msg;

    ApiCode(final long code, final String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ApiCode fromCode(long code) {
        ApiCode[] ecs = ApiCode.values();
        for (ApiCode ec : ecs) {
            if (ec.getCode() == code) {
                return ec;
            }
        }
        return SUCCESS;
    }

    @Override
    public long getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        return String.format(" ErrorCode:{code=%s, msg=%s} ", code, msg);
    }
}